package org.freez4.spring.event;

import org.springframework.context.*;
import org.springframework.context.support.GenericApplicationContext;


/**
 * {@link ApplicationListener} 简单示例
 *
 * @author 阿坤同学
 * @return
 * @date 2024/2/17 17:42
 * @see ApplicationListener
 */
public class ApplicationListenerSimpleDemo {

    public static void main(String[] args) {
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.addApplicationListener(event -> System.out.println("onApplicationEvent - 接收到 Spring ApplicationEvent：" + event));

        // 启动 Spring 应用上下文
        applicationContext.refresh(); // ContextRefreshedEvent
        // 启动 Spring 上下文
        applicationContext.start();  // ContextStartedEvent
        // 停止 Spring 上下文
        applicationContext.stop();  // ContextStoppedEvent
        // 关闭 Spring 应用上下文
        applicationContext.close(); // ContextClosedEvent
    }

}